import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;

/**
 * Created with IntelliJ IEDA.
 * Description:
 * User:86186
 * Date:2022-12-21
 * Time:15:18
 */
/*
* 使用这个类来封装 DataSource 单例
* 懒汉模式
* */
public class DBUtil {
    private static volatile DataSource dataSource = null;

    public static DataSource getDataSource(){
       if (dataSource == null){
           synchronized (DBUtil.class){
               if (dataSource == null){
                   dataSource = new MysqlDataSource();
                   ((MysqlDataSource)dataSource).setUrl("jdbc:mysql://127.0.0.1:3306/java105?characterEncoding=utf8&useSSL=false");
                   ((MysqlDataSource)dataSource).setUser("root");
                   ((MysqlDataSource)dataSource).setPassword("wgz20030828");
               }
           }
       }
        return dataSource;
    }

    private DBUtil(){

    }
}
